<?php

namespace app\admin\model\trades\assets;

use think\Model;


class Withdrawsrelcard extends Model
{


    const STATE_1 = 1;//已到账
    const STATE_2 = 2;//处理中
    const STATE_3 = 3;//已取消



    // 表名
    protected $table = 'activity_withdraws';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'ctime_text',
        'check_time_text',
        'state_text',
    ];




    //状态标志
    public function getStateList()
    {
        return ['1' => __('state 1'),'2' => __('state 2'),'3' => __('state 3')];
    }



    //获取状态类型
    public function getStateTextAttr($value, $data)
    {
        $value = $value ? $value : $data['state'];
        $list = $this->getStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getCtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['ctime']) ? $data['ctime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getCheckTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['check_time']) ? $data['check_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setCtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setCheckTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function accountcard()
    {
        return $this->belongsTo('app\admin\model\trades\assets\Card', 'card_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
